package com.banciyuan.bcywebview.base.helper.timelinedatacenter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.factory.TimelineFactory;
import com.banciyuan.bcywebview.biz.detail.complex.ComplexDetailActivity;
import com.banciyuan.bcywebview.biz.detail.mixweb.MixWebActivity;
import com.banciyuan.bcywebview.biz.detail.noveldetail.newnoveldetail.NovelComplexActivity;
import com.banciyuan.bcywebview.biz.detail.post.PostDetailActivity;
import com.banciyuan.bcywebview.utils.constants.MyConstants;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;

import de.greenrobot.daoexample.model.Complex;
import de.greenrobot.daoexample.model.DetailType;
import de.greenrobot.daoexample.model.Recommend;
import de.greenrobot.daoexample.model.Timeline;

/**
 * Created by hy on 2015/11/5.
 */
public class DetailDataHelper {
    /**
     * 去cos detial页
     *
     * @param context
     * @param rp_id
     * @param cp_id
     * @param fromComment 是否跳评论
     */

    public static Intent creatCosDetail(Context context, String rp_id, String cp_id, boolean fromComment, boolean goComment) {
        Intent intent = new Intent(context, ComplexDetailActivity.class);
        intent.putExtra(MyConstants.RPIDVALUE, rp_id);
        intent.putExtra(MyConstants.CPIDVALUE, cp_id);
        intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_COSER);
        if (fromComment) {
            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, "fromComment");
        }
        if (goComment) {
            intent.putExtra("pushSource", goComment);
        }
        return intent;
    }

    public static void gotoCosDetail(Context context, String rp_id, String cp_id, boolean fromComment) {
        context.startActivity(creatCosDetail(context, rp_id, cp_id, fromComment, false));
    }

    public static void gotoCosDetail(Context context, String rp_id, String cp_id, boolean fromComment, boolean goComment) {
        context.startActivity(creatCosDetail(context, rp_id, cp_id, fromComment, goComment));
    }

    /**
     * 去绘画 detial页
     *
     * @param context
     * @param rp_id
     * @param dp_id
     * @param fromComment 是否跳评论
     */
    public static Intent creatDrawerDetail(Context context, String rp_id, String dp_id, boolean fromComment, boolean goComment) {
        Intent intent = new Intent(context, ComplexDetailActivity.class);
        intent.putExtra(MyConstants.RPIDVALUE, rp_id);
        intent.putExtra(MyConstants.DPIDVALUE, dp_id);
        intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_ILLUST);
        if (fromComment) {
            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, "fromComment");
        }
        if (goComment) {
            intent.putExtra("pushSource", goComment);
        }

        return intent;
    }

    public static void gotoDrawerDetail(Context context, String rp_id, String dp_id, boolean fromComment, boolean goComment) {
        context.startActivity(creatDrawerDetail(context, rp_id, dp_id, fromComment, goComment));
    }

    /**
     * 去绘画 detial页
     *
     * @param context
     * @param rp_id
     * @param dp_id
     * @param fromComment 是否跳评论
     */
    public static void gotoDrawerDetail(Context context, String rp_id, String dp_id, boolean fromComment) {
        context.startActivity(creatDrawerDetail(context, rp_id, dp_id, fromComment, false));
    }

    /**
     * 去写作 detial页
     *
     * @param context
     * @param rp_id
     * @param wp_id
     * @param fromComment 是否跳评论
     */


    public static Intent createWriterDetail(Context context, String rp_id, String wp_id, boolean fromComment, boolean goComment, boolean fromNovelIndex) {
        Intent intent = new Intent(context, NovelComplexActivity.class);
        intent.putExtra(MyConstants.RPIDVALUE, rp_id);
        intent.putExtra(MyConstants.WPIDVALUE, wp_id);
        intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_WRITER);
        if (fromComment) {
            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, "fromComment");
        }
        if (goComment) {
            intent.putExtra("pushSource", goComment);
        }
        if (fromNovelIndex) {
            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, "novelindex");
        }
        return intent;
    }


    public static void gotoWriterDetail(Context context, String rp_id, String wp_id, boolean fromComment) {
        context.startActivity(createWriterDetail(context, rp_id, wp_id, fromComment, false, false));
    }

    /**
     * 去写作 detial页
     *
     * @param context
     * @param rp_id
     * @param wp_id
     * @param fromComment 是否跳评论
     */
    public static void gotoWriterDetail(Context context, String rp_id, String wp_id, boolean fromComment, boolean goComment) {
        context.startActivity(createWriterDetail(context, rp_id, wp_id, fromComment, goComment, false));
    }

    /**
     * 去写作 detial页的第二种方式
     *
     * @param context
     * @param rp_id
     * @param wp_id
     * @param wns_id
     * @param fromNovelIndex
     */
    public static void gotoWriterDetail(Context context, String rp_id, String wp_id, String wns_id, boolean fromNovelIndex) {
        Intent intent = new Intent(context, NovelComplexActivity.class);
        intent.putExtra(MyConstants.RPIDVALUE, rp_id);
        intent.putExtra(MyConstants.WPIDVALUE, wp_id);
        intent.putExtra(gotoUtil.INTENT_VALUE_TWO, wns_id);
        intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_WRITER);
        if (fromNovelIndex) {
            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, "novelindex");
        }
        context.startActivity(intent);
    }


    /**
     * 去日常新鲜事 detial页
     *
     * @param context
     * @param ud_id
     * @param fromComment 是否跳评论
     */

    public static Intent createDailyDetail(Context context, String ud_id, boolean fromComment, boolean goComment) {
        Intent intent = new Intent(context, ComplexDetailActivity.class);
        intent.putExtra(MyConstants.UDIDVALUE, ud_id);
        intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_DAILY);
        if (fromComment) {
            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, "fromComment");
        }
        if (goComment) {
            intent.putExtra("pushSource", goComment);
        }
        return intent;
    }


    public static Intent createDailyDetailActicleWithData(Context context, String ud_id, boolean fromComment, boolean goComment, Complex complex) {
        Intent intent = new Intent(context, MixWebActivity.class);
        intent.putExtra(MyConstants.UDIDVALUE, ud_id);
        intent.putExtra("complex", complex);
        intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_DAILY);
        Log.i("fromComment", fromComment + "");
        if (fromComment) {
            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, "fromComment");
        }
        if (goComment) {
            intent.putExtra("pushSource", goComment);
        }
        return intent;
    }

    public static void gotoDailyDetail(Context context, String ud_id, boolean fromComment) {
        context.startActivity(createDailyDetail(context, ud_id, fromComment, false));
    }

    public static void gotoDailyDetailActicle(Activity activity, String ud_id, boolean fromComment, Complex complex) {
        activity.startActivity(createDailyDetailActicleWithData(activity, ud_id, fromComment, false, complex));
        activity.overridePendingTransition(R.anim.fast_fade_in, R.anim.fast_fade_out);
    }

    /**
     * 去日常新鲜事 detial页
     *
     * @param context
     * @param ud_id
     * @param fromComment 是否跳评论
     */
    public static void gotoDailyDetail(Context context, String ud_id, boolean fromComment, boolean goComment) {
        context.startActivity(createDailyDetail(context, ud_id, fromComment, goComment));
    }

    /**
     * 去小组 detial页
     *
     * @param context
     * @param gid
     * @param post_id
     * @param fromComment 是否跳评论
     */

    public static Intent createGroupDetail(Context context, String gid, String post_id, boolean fromComment, boolean goComment) {
        Intent intent = new Intent(context, PostDetailActivity.class);
        intent.putExtra(MyConstants.GIDVALUE, gid);
        intent.putExtra(MyConstants.POSTIDVALUE, post_id);
        intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_GROUP);
        if (fromComment) {
            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, "fromComment");
        }
        if (goComment) {
            intent.putExtra("pushSource", goComment);
        }
        return intent;
    }

    public static void gotoGroupDetail(Context context, String gid, String post_id, boolean fromComment) {
        context.startActivity(createGroupDetail(context, gid, post_id, fromComment, false));
    }

    /**
     * 去小组 detial页
     *
     * @param context
     * @param gid
     * @param post_id
     * @param fromComment 是否跳评论
     */
    public static void gotoGroupDetail(Context context, String gid, String post_id, boolean fromComment, boolean goComment) {
        context.startActivity(createGroupDetail(context, gid, post_id, fromComment, goComment));

    }

    public static void putBaseDetailValue(Intent intent, DetailType mDetailType) {
        switch (mDetailType.getTimelineType()) {
            case TimelineFactory.TIMELINE_TYPE_COSER:
                intent.putExtra(MyConstants.RPIDVALUE, mDetailType.getRp_id());
                intent.putExtra(MyConstants.CPIDVALUE, mDetailType.getCp_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_COSER);
                break;
            case TimelineFactory.TIMELINE_TYPE_ILLUST:
                intent.putExtra(MyConstants.RPIDVALUE, mDetailType.getRp_id());
                intent.putExtra(MyConstants.DPIDVALUE, mDetailType.getDp_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_ILLUST);
                break;
            case TimelineFactory.TIMELINE_TYPE_DAILY:
                intent.putExtra(MyConstants.UDIDVALUE, mDetailType.getUd_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_DAILY);
                break;
            case TimelineFactory.TIMELINE_TYPE_GROUP:
                intent.putExtra(MyConstants.GIDVALUE, mDetailType.getGid());
                intent.putExtra(MyConstants.POSTIDVALUE, mDetailType.getPost_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_GROUP);
                break;
            case TimelineFactory.TIMELINE_TYPE_WRITER:
                intent.putExtra(MyConstants.RPIDVALUE, mDetailType.getRp_id());
                intent.putExtra(MyConstants.WPIDVALUE, mDetailType.getWp_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_WRITER);
                break;
        }
    }

    public static void putBaseDetailValue(Intent intent, Timeline timeline) {
        switch (timeline.getTimelineType()) {
            case TimelineFactory.TIMELINE_TYPE_COSER:
                intent.putExtra(MyConstants.RPIDVALUE, timeline.getRp_id());
                intent.putExtra(MyConstants.CPIDVALUE, timeline.getCp_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_COSER);
                break;
            case TimelineFactory.TIMELINE_TYPE_ILLUST:
                intent.putExtra(MyConstants.RPIDVALUE, timeline.getRp_id());
                intent.putExtra(MyConstants.DPIDVALUE, timeline.getDp_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_ILLUST);
                break;
            case TimelineFactory.TIMELINE_TYPE_DAILY:
                intent.putExtra(MyConstants.UDIDVALUE, timeline.getUd_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_DAILY);
                break;
            case TimelineFactory.TIMELINE_TYPE_GROUP:
                intent.putExtra(MyConstants.GIDVALUE, timeline.getGid());
                intent.putExtra(MyConstants.POSTIDVALUE, timeline.getPost_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_GROUP);
                break;
            case TimelineFactory.TIMELINE_TYPE_WRITER:
                intent.putExtra(MyConstants.RPIDVALUE, timeline.getRp_id());
                intent.putExtra(MyConstants.WPIDVALUE, timeline.getWp_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_WRITER);
                break;
            case TimelineFactory.TIMELINE_TYPE_GOODS:
                intent.putExtra(MyConstants.ZGIDVALUE, timeline.getZg_id());
                intent.putExtra(MyConstants.TIMELINETYPE, TimelineFactory.TIMELINE_TYPE_GOODS);
                break;
        }
    }


    public static void getBaseDetailVaule(DetailType mDetailType, Intent intent) {
        String rp_id;
        String cp_id;
        String wp_id;
        String dp_id;
        String ud_id;
        String gid;
        String post_id;
        int timelineType = intent.getIntExtra(MyConstants.TIMELINETYPE, 0);
        switch (timelineType) {
            case TimelineFactory.TIMELINE_TYPE_COSER:
                rp_id = intent.getStringExtra(MyConstants.RPIDVALUE);
                cp_id = intent.getStringExtra(MyConstants.CPIDVALUE);
                mDetailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_COSER);
                mDetailType.setRp_id(rp_id);
                mDetailType.setCp_id(cp_id);
                break;
            case TimelineFactory.TIMELINE_TYPE_ILLUST:
                rp_id = intent.getStringExtra(MyConstants.RPIDVALUE);
                dp_id = intent.getStringExtra(MyConstants.DPIDVALUE);
                mDetailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_ILLUST);
                mDetailType.setRp_id(rp_id);
                mDetailType.setDp_id(dp_id);
                break;
            case TimelineFactory.TIMELINE_TYPE_DAILY:
                ud_id = intent.getStringExtra(MyConstants.UDIDVALUE);
                mDetailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_DAILY);
                mDetailType.setUd_id(ud_id);
                break;
            case TimelineFactory.TIMELINE_TYPE_GROUP:
                gid = intent.getStringExtra(MyConstants.GIDVALUE);
                post_id = intent.getStringExtra(MyConstants.POSTIDVALUE);
                mDetailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_GROUP);
                mDetailType.setGid(gid);
                mDetailType.setPost_id(post_id);
                break;
            case TimelineFactory.TIMELINE_TYPE_WRITER:
                rp_id = intent.getStringExtra(MyConstants.RPIDVALUE);
                wp_id = intent.getStringExtra(MyConstants.WPIDVALUE);
                mDetailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_WRITER);
                mDetailType.setRp_id(rp_id);
                mDetailType.setWp_id(wp_id);
                break;
            default:
                break;
        }
    }

    public static DetailType gotoViewPic(Timeline timeline) {
        DetailType detailType = new DetailType();
        detailType.setRp_id(timeline.getRp_id());
        detailType.setCp_id(timeline.getCp_id());
        detailType.setUd_id(timeline.getUd_id());
        detailType.setPost_id(timeline.getPost_id());
        detailType.setTimelineType(timeline.getTimelineType());
        return detailType;
    }

    public static DetailType gotoViewPic(Complex timeline) {
        DetailType detailType = new DetailType();
        detailType.setRp_id(timeline.getRp_id());
        detailType.setCp_id(timeline.getCp_id());
        detailType.setUd_id(timeline.getUd_id());
        detailType.setPost_id(timeline.getPost_id());
        detailType.setTimelineType(timeline.getTimelineType());
        return detailType;
    }

    public static DetailType parseRecommenndToDetailType(Recommend.InnerData innerData, String type) {
        DetailType detailType = new DetailType();
        if (type.equals("group_post")) {
            detailType.setPost_id(innerData.getPost_id());
            detailType.setGid(innerData.getGid());
            detailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_GROUP);
        } else if (type.equals("cos")) {
            detailType.setRp_id(innerData.getRp_id());
            detailType.setCp_id(innerData.getCp_id());
            detailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_COSER);
        } else if (type.equals("illust")) {
            detailType.setRp_id(innerData.getRp_id());
            detailType.setDp_id(innerData.getDp_id());
            detailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_ILLUST);
        } else if (type.equals("novel")) {
            detailType.setRp_id(innerData.getRp_id());
            detailType.setWp_id(innerData.getWp_id());
            detailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_WRITER);
        } else if (type.equals("daily")) {
            detailType.setUd_id(innerData.getUd_id());
            detailType.setTimelineType(TimelineFactory.TIMELINE_TYPE_DAILY);
        }
        return detailType;
    }
}